package cn.tedu.bece.front.controller;

import cn.tedu.bece.front.common.response.JsonResult;
import cn.tedu.bece.front.pojo.dto.DiaryQuery;
import cn.tedu.bece.front.pojo.dto.DiarySaveParam;
import cn.tedu.bece.front.pojo.vo.DiaryVO;
import cn.tedu.bece.front.service.DiaryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@RestController
@RequestMapping("/api/diary")
public class DiaryController {
    @Autowired
    DiaryService diaryService;

    @PostMapping("save")
    public JsonResult saveDiary(@RequestBody DiarySaveParam diarySaveParam){
        log.debug("保存日记：diarySaveParam={}",diarySaveParam);
        diaryService.saveDiary(diarySaveParam);
        return JsonResult.success();
    }

    @GetMapping("select")
    public JsonResult selectDiary(DiaryQuery diaryQuery){
        log.debug("查询日记：diaryQuery={}",diaryQuery);
        List<DiaryVO> list = diaryService.selectDiary(diaryQuery);
        return JsonResult.success(list);
    }
}
